package com.ymatou.iapi.godmch.testcase;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.internal.runners.TestMethod;

import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.godmch.parameter.CreateCodeBean;
import com.ymatou.iapi.godmch.parameter.createIndepMchBean;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.parameter.editmchBean;
import com.ymatou.iapi.godmch.parameter.getAgentIdListByMerchantIdAndTitleBean;
import com.ymatou.iapi.godmch.service.applyAgentCall;
import com.ymatou.iapi.godmch.service.createIndepMchCall;
import com.ymatou.iapi.godmch.service.getAgentIdListByMerchantIdAndTitleCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.utils.TestDataManager;
/**
*根据代理名称模糊查询商户的代理商id列表
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getAgentIdListByMerchantIdAndTitle{
	private static getAgentIdListByMerchantIdAndTitleBean bean;
	private static getAgentIdListByMerchantIdAndTitleCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据代理名称模糊查询商户的代理商id列表");
	}

	@Before
	public void caseUp() {
		bean=new getAgentIdListByMerchantIdAndTitleBean();
		call=new getAgentIdListByMerchantIdAndTitleCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getAgentIdListByMerchantIdAndTitle_001() {
		Logger.start(true,"根据代理名称模糊查询商户的代理商id列表-平台商户代理");
		try {
			
			CreateCodeBean ccbean = GodmchManageCallService.CreateAllMsgSellerMch();
			String code = GodmchManageCallService.createCodeCall(ccbean).getCode();
			Integer agentid = GodmchManageCallService.CreateSellerMch(code);
			
			editmchBean editmchbean = GodmchManageCallService.IniteditmachBean(agentid);
			editmchbean.setMchTitle("自动化测试_"+TestDataManager.getRandomIntNum(5));
			GodmchManageCallService.editmachCall(editmchbean);
			
			bean.setMerchantId(ccbean.getMchId());
			bean.setTitle(editmchbean.getMchTitle());
			
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
	        Logger.verifyEquals(agentid, call.getAgentIdList().getInt(0), "验证返回成功AgentId值");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getAgentIdListByMerchantIdAndTitle_002() {
		Logger.start(true,"根据代理名称模糊查询商户的代理商id列表-独立商户代理");
		try {
			
//			CreateCodeBean ccbean = GodmchManageCallService.CreateAllMsgSellerMch();
//			String code = GodmchManageCallService.createCodeCall(ccbean).getCode();
//			Integer agentid = GodmchManageCallService.CreateSellerMch(code);
//			
//			editmchBean editmchbean = GodmchManageCallService.IniteditmachBean(agentid);
//			editmchbean.setMchTitle("自动化测试_"+TestDataManager.getRandomIntNum(5));
//			GodmchManageCallService.editmachCall(editmchbean);
			
			
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
			
			applyAgentCall applyAgentCall=GodmchManageCallService.applyAndapproveAgent(createIndepMchCall.getmchId());
			
			editmchBean editmchbean = GodmchManageCallService.IniteditmachBean(applyAgentCall.getAgentId());
			editmchbean.setMchTitle("自动化测试_"+TestDataManager.getRandomIntNum(5));
			GodmchManageCallService.editmachCall(editmchbean);
			
			bean.setMerchantId(createIndepMchCall.getmchId());
			bean.setTitle("自动化测试");
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证返回成功status值");
	        Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
	        Logger.verifyEquals(applyAgentCall.getAgentId(), call.getAgentIdList().getInt(0), "验证返回成功AgentId值");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getAgentIdListByMerchantIdAndTitle_003() {
		Logger.start(true,"根据代理名称模糊查询商户的代理商id列表-Title为空");
		try {

			CreateCodeBean ccbean = GodmchManageCallService.CreateAllMsgSellerMch();
			String code = GodmchManageCallService.createCodeCall(ccbean).getCode();
			Integer agentid = GodmchManageCallService.CreateSellerMch(code);
			
			editmchBean editmchbean = GodmchManageCallService.IniteditmachBean(agentid);
			editmchbean.setMchTitle("自动化测试_"+TestDataManager.getRandomIntNum(5));
			GodmchManageCallService.editmachCall(editmchbean);
			
			bean.setMerchantId(ccbean.getMchId());
		//	bean.setTitle("自动化测试");
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证返回成功status值");	
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getAgentIdListByMerchantIdAndTitle_004() {
		Logger.start(true,"根据代理名称模糊查询商户的代理商id列表-MerchantId为空");
		try {

			CreateCodeBean ccbean = GodmchManageCallService.CreateAllMsgSellerMch();
			String code = GodmchManageCallService.createCodeCall(ccbean).getCode();
			Integer agentid = GodmchManageCallService.CreateSellerMch(code);
			
			editmchBean editmchbean = GodmchManageCallService.IniteditmachBean(agentid);
			editmchbean.setMchTitle("自动化测试_"+TestDataManager.getRandomIntNum(5));
			GodmchManageCallService.editmachCall(editmchbean);
			
			//bean.setMerchantId(ccbean.getMchId());
			bean.setTitle("自动化测试");
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证返回成功status值");	
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}